Give this a try: I didn't know what direction you sorted in, so I assumed highest to lowest (if that's not right, just change sortDirection to 1). Run the command: !gurps-init If you have tokens selected, the ones that qualify will become the initiative order. If you don't have any selected, it will build the initiative order off all the qualifying tokens on the current page that represent a character and are on the objects or GM layer. on('ready',function(){
'use strict';
var initAttr = 'speed',
sortDirection = -1;
on('chat:message',function(msg){
if('api' === msg.type && msg.content.match(/^!gurps-init/) && playerIsGM(msg.playerid) ){
let pageid=getObj('player',msg.playerid).get('lastpage'),
selectedIDs = _.pluck(msg.selected,'_id');
Campaign().set('turnorder',JSON.stringify(_.chain(
filterObjs(
selectedIDs.length ?
(o)=>_.contains(selectedIDs,o.id) :
(o)=>o.get('type')==='graphic' && o.get('pageid')===pageid && _.contains(['objects','gmlayer'],o.get('layer')) && o.get('represents') !== ''
)
)
.map(
(t)=>({ tokenid: t.id, characterid: t.get('represents'), initAttr: parseFloat(getAttrByName(t.get('represents'),initAttr,'current'))})
)
.reject((o)=>_.isUndefined(o.initAttr) || _.isNull(o.initAttr) || _.isNaN(o.initAttr) || !o.initAttr)
.sort((o)=>(sortDirection*o.initAttr))
.map((o)=>({id: o.tokenid, pr: o.initAttr.toFixed(2), custom:''}))
.value()
));
}
});
});
Cheers! =D